/*
 * Copyright (c) 2024 Huawei Technologies Co., Ltd.
 * openUBMC is licensed under Mulan PSL v2.
 * You can use this software according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of Mulan PSL v2 at:
 *         http://license.coscl.org.cn/MulanPSL2
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PSL v2 for more details.
 */

#ifndef I_SCANNER_H
#define I_SCANNER_H

#include <device_tree/interface/Scanner.h>
#include <mc/core/timer.h>
#include <mc/debounce/base.h>
#include <memory>

// Scanner状态码定义
#define SCANNER_OK 0           // 正常
#define SCANNER_FAILURE 1      // 失败
#define SCANNER_PRE_FAILURE 2  // 预失败
#define SCANNER_STOPPED 3      // 停止/禁用

namespace dev {

class IScanner : public mc::engine::interface<IScanner, gen::Scanner> {
public:
    IScanner()  = default;
    ~IScanner() = default;
    void start_scanner_task();
    void stop_scanner_task();
    bool init_debounce_config();
    void init_scanner_signal();

private:
    void                                update_scanner_task();
    void                                handle_result_failure();
    void                                handle_result_success(uint64_t value);
    mc::core::timer*                    m_scanner_timer = nullptr;
    std::unique_ptr<mc::debounce::Base> debounce;
    uint8_t                             success_count{0}; // 成功计数
    uint8_t                             failure_count{0}; // 失败计数
};

} // namespace dev

#endif // I_SCANNER_H
